package com.emm.yixun.mobile.adapter;

import com.emm.yixun.mobile.model.GetPayDepositList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.emm.yixun.mobile.R;

public class FromListAdapter extends BaseAdapter {

	Context context;
	GetPayDepositList date;

	public FromListAdapter(Context context, GetPayDepositList date) {
		this.context = context;
		this.date = date;
	}

	public void SetDate(GetPayDepositList date) {
		this.date = date;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		if (date == null) {
			return 0;
		} else {
			if (null == date.getPayDepositList()) {
				return 0;
			} else {
				return date.getPayDepositList().size();
			}
		}
	}

	@Override
	public Object getItem(int position) {
		return date == null ? null : date.getPayDepositList().get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoudler v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.fromlist_item, null);
			v = new ViewHoudler();
			v.icon_type = (ImageView) convertView.findViewById(R.id.icon_type);
			v.name_content = (TextView) convertView.findViewById(R.id.name_content);
			v.tvTag = convertView.findViewById(R.id.tv_tag);
			v.times = (TextView) convertView.findViewById(R.id.times);
			v.top_linear = (LinearLayout) convertView.findViewById(R.id.top_linear);
			convertView.setTag(v);
		} else {
			v = (ViewHoudler) convertView.getTag();
		}

		final String recordBusiness = date.getPayDepositList().get(position).getRecordBusiness();
		v.tvTag.setText(recordBusiness);

		final boolean isApply = "认筹".equals(recordBusiness);

		if (isApply) {
			v.top_linear.setBackgroundResource(R.drawable.mode_from_list_orange);
			v.tvTag.setBackgroundResource(R.drawable.shape_solid_orange_corners_large);
		} else {
			v.top_linear.setBackgroundResource(R.drawable.mode_from_list_gray);
			v.tvTag.setBackgroundResource(R.drawable.shape_solid_gray_corners_large);
		}

		if ("1".equals(date.getPayDepositList().get(position).getIsPayDeposit())) {
			v.name_content.setText(context.getString(R.string.hint_text_content_fromlist));
		} else {
			v.name_content.setText(date.getPayDepositList().get(position).getPayDepositHouses());
		}

		v.times.setText(date.getPayDepositList().get(position).getPayDepositTime());
		// 0、待提交；1、审核中；2、驳回；3、成功
		// 审核状态：0、待提交；1、审核中；2、已退回；3、已通过
		if ("待提交".equals(date.getPayDepositList().get(position).getAuditStatus())) {
			v.icon_type.setImageResource(R.drawable.icon_submit);
		} else if ("审核中".equals(date.getPayDepositList().get(position).getAuditStatus())) {
			v.icon_type.setImageResource(R.drawable.icon_revie);
		} else if ("已退回".equals(date.getPayDepositList().get(position).getAuditStatus())) {
			v.icon_type.setImageResource(R.drawable.icon_back);
		} else {// if
				// ("3".equals(date.getPayDepositList().get(position).getAuditStatus()))
			v.icon_type.setImageResource(R.drawable.icon_sucss);
		}
		return convertView;
	}

	public static class ViewHoudler {
		TextView name_content;
		TextView times;
		TextView tvTag;
		ImageView icon_type;
		LinearLayout top_linear;
	}
}
